package com.ruoyi.yljf.controller.AppController;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.security.annotation.Anonymous;
import com.ruoyi.yljf.domain.Comment;
import com.ruoyi.yljf.domain.dto.CommentDTO;
import com.ruoyi.yljf.domain.vo.CourseCommentVO;
import com.ruoyi.yljf.domain.vo.QuestionVO;
import com.ruoyi.yljf.domain.vo.RedMoreVO;
import com.ruoyi.yljf.service.ICommentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * 评论相关Controller
 *
 * @author metaee
 * @date 2025-02-14
 */
@RestController
@RequestMapping("api/CourseComment")
public class ApiCourseCommentController extends BaseController {

    @Autowired
    private ICommentService commentService;
    
    
    /**
     * 查询当前文章的回复列表
     * @return
     */
    @GetMapping("/getCourseReplyList")
    @Anonymous
    public TableDataInfo getCourseReplyList(CommentDTO dto, HttpServletRequest request){
        startPage();
        List<Comment> list  = commentService.queryList(dto);
        List<CourseCommentVO> result =  commentService.courseReplyList(list,request);
        return getDataTableInfo(result,list);
    }

    /**
     * 查询某个评论下面的所有回复
     * @return
     */
    @GetMapping("/readMore/{commentId}")
    @Anonymous
    public AjaxResult readMore(@PathVariable("commentId") Long commentId){
        List<Comment> list = commentService.selectByParentId(commentId);
        List<RedMoreVO> result =  commentService.readMore(list);
        return AjaxResult.success(result);
    }

    /**
     * 评论点赞
     * @param req：获取当前用户信息
     * @param commentId：点赞评论id
     * @return
     */
    @PostMapping("/like")
    public AjaxResult like(HttpServletRequest req, Long commentId){
        return commentService.like(commentId, req);
    }

}
